﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.Mvc;
using YaAppoint.Devices;

namespace YaAppoint.Web.Controllers
{
    /// <summary>
    /// 检查设备控制器
    /// </summary>
    public class DeviceController(IDeviceAppService deviceAppService) : AbpController
    {
        private readonly IDeviceAppService _deviceAppService = deviceAppService;

        /// <summary>
        /// 加载Tree数据
        /// </summary>
        [HttpGet("/api/device/get-tree-data")]
        public async Task<IActionResult> GetTreeData(Guid? depId)
        { 
            return new JsonResult(await _deviceAppService.GetTreeData(depId));
        }

        /// <summary>
        /// 加载设备类型选项
        /// </summary>
        [HttpGet("/api/device/get-device-type-options")]
        public async Task<IActionResult> GetDeviceTypeOptions(Guid depId)
        {
            return new JsonResult(await _deviceAppService.GetDeviceTypeOptions(depId));
        }

        /// <summary>
        /// 加载状态选项
        /// </summary>
        [HttpGet("/api/device/get-status-options")]
        public IActionResult LoadStatusOptions()
        {
            return new JsonResult(_deviceAppService.LoadStatusOptions());
        }

        /// <summary>
        /// 获取诊室下设备
        /// </summary>
        [HttpGet("/api/device/get-room-devices")]
        public async Task<IActionResult> GetRoomDevicesAsync(Guid roomId)
        {
            return new JsonResult(await _deviceAppService.GetRoomDevicesAsync(roomId));
        }

        /// <summary>
        /// 获取设备详情
        /// </summary>
        [HttpGet("/api/device/get")]
        public async Task<IActionResult> GetAsync(Guid id)
        {
            return new JsonResult(await _deviceAppService.GetDetailAsync(id));
        }

        /// <summary>
        ///  提交创建
        /// </summary>
        [HttpPost("/api/device/submit-create")]
        public async Task<IActionResult> SubmitCreate([FromBody] DeviceDto dto, Guid roomId)
        {
            return new JsonResult(await _deviceAppService.SubmitCreate(dto, roomId));
        }

        /// <summary>
        /// 提交编辑
        /// </summary>
        [HttpPost("/api/device/submit-edit")]
        public async Task<IActionResult> SubmitEdit([FromBody]DeviceDto dto,[FromQuery]Guid roomId)
        {
            return new JsonResult(await _deviceAppService.SubmitEdit(dto,roomId));
        }

        /// <summary>
        /// 删除设备
        /// </summary>
        [HttpGet("/api/device/delete")]
        public async Task<IActionResult> DeleteAsync(Guid id)
        {
            return new JsonResult(await _deviceAppService.DeleteAsync(id));
        }

        /// <summary>
        /// 获取排班计划选项
        /// </summary>
        [HttpGet("/api/device/get-schedule-options")]
        public async Task<IActionResult> GetScheduleOptions(Guid deviceId)
        {
            return new JsonResult(await _deviceAppService.GetScheduleOptions(deviceId));
        }
    }
}
